package lab03.Test12;

import java.beans.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by lenovo on 2017/12/13.
 */
public class test {
    public static void main(String[] args) {


        //3+1
        Connection connection = null;
        java.sql.Statement statement = null;
        boolean resultSet = Boolean.parseBoolean(null);

        String sql = "select * from t_users";

/*12、	简单SQL语句练习，以下操作均建立在上述t_users 用户表的基础上。
1)	查询所有记录；
2)	查询用户名为'admin'的记录；
3)	查询用户名为'admin'，密码为'123456'的记录；
4)	查询注册时间大于10000000的记录；
*/

        try {
            Class.forName("com.mysql.cj.jdbc.Driver");

            connection = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/java_2017?serverTimezone=UTC",
                    "root",
                    "123456"
            );

            statement =connection.createStatement();
            resultSet = statement.execute("SELECT * FROM t_users WHERE username = 'chen' AND password = '123456'");
            resultSet = statement.execute("SELECT * FROM t_users WHERE register_datetime > '10000000'");
            //ResultSet：“查”

            statement.execute(sql);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }}
